Raspberry Pi K8sクラスタworkerの作成
基本的には、ラズパイ4で作るディスプレイ付きKubernetesクラスターの手順で作業する。
Raspberry Pi OSのインストール
詳細は省略する。
Raspberry Pi OSでの初期設定
イメージを焼いたホストOSで以下のように設定を行う。
SSHの起動設定をする。
code:shell
% touch /Volumes/boot/ssh
K8sが要求するcgroupに関する設定をする。
注意:もとからある内容に追記してください。
code:boot/cmdline.txtへの追加
cgroup_enable=cpuset cgroup_enable=memory cgroup_memory=1
microSDカードをRaspberry Piに刺し、起動する。
K8sが要求するswapの無効化を行う。
code:shell
$ sudo systemctl disable dphys-swapfile.service
sudo: ホスト raspberrypi の名前解決ができません: 名前またはサービスが不明です
Synchronizing state of dphys-swapfile.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install disable dphys-swapfile
Removed /etc/systemd/system/multi-user.target.wants/dphys-swapfile.service.
パスワードの変更をする。
code:shell
$ passwd
ホスト名の設定をする。
code: /etc/hostname
worker-rpi4
code:/etc/hosts
127.0.1.1 worker-rpi4
固定IPの設定をする。
code:/etc/dhcpcd.conf.diff
$ diff -u /etc/dhcpcd.conf{.org,}
--- /etc/dhcpcd.conf.org 2020-12-09 07:37:09.443471319 +0900
+++ /etc/dhcpcd.conf 2020-12-09 07:38:44.100227317 +0900
@@ -57,3 +57,13 @@
# fallback to static profile on eth0
#interface eth0
#fallback static_eth0
+
+interface wlan0
+static ip_address=192.168.3.102/24
+static routers=192.168.3.1
+static domain_name_servers=8.8.8.8
+
+interface eth0
+static ip_address=192.168.2.102/24
+static routers=192.168.2.1
+static domain_name_servers=8.8.8.8
パッケージを最新にする。
code:shell
$ apt update
$ apt upgrade
作業用に必要なパッケージをインストールする。
code:shell
$ apt install -y tmux stress
一度、再起動をしておく。
Dockerのインストール
Install Docker Engine on Ubuntuに従う。
既に、インストールされているdockerがあれば、削除する。
code:shell
$ sudo apt-get remove docker docker-engine docker.io containerd runc
Dockerのインストールに必要なパッケージをインストールする。
code:shell
$ sudo apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common
Docker公式のキーを登録し、内容を確認する。
code:shell
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo apt-key fingerprint 0EBFCD88
pub rsa4096 2017-02-22 SCEA
9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
uid 不明 Docker Release (CE deb) <docker@docker.com>
sub rsa4096 2017-02-22 S
Dockerのパッケージ用のリポジトリを登録する。
code:shell
$ echo "deb arch=armhf https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list
deb arch=armhf https://download.docker.com/linux/raspbian buster stable
Dockerのパッケージをインストールする。
code:shell
$ sudo apt update
$ sudo apt-get install -y docker-ce docker-ce-cli containerd.io
K8sのインストール
kubeadmのインストールの手順に従う。
K8sのインストールに要求されるパッケージをインストールする。
code:shell
$ sudo apt-get install -y apt-transport-https curl
K8sインストールに必要なキーを登録する。
code:shell
$ curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
K8sのリポジトリを登録する。
code:shell
$ echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
K8sのパッケージをインストールする。
code:shell
$ sudo apt-get update
$ sudo apt-get install -y kubelet kubeadm kubectl
K8sパッケージが更新されないように、バージョンを固定する。
code:shell
$ sudo apt-mark hold kubelet kubeadm kubectl
Workerノードの構築
はじめに、masterノードで接続情報を確認する。
この情報は、24時間で無効となり更新されるため、毎回確認することが望ましい。
code:shell
pi@master-rpi4$ kubeadm token create --print-join-command
W1209 08:19:26.237404 26590 configset.go:348] WARNING: kubeadm cannot validate component configs for API groups kubelet.config.k8s.io kubeproxy.config.k8s.io
kubeadm join 192.168.3.101:6443 --token cgn745.x8gzni9rgwcuqub5 --discovery-token-ca-cert-hash sha256:511f26c4010e4d54e2f8ebafb16204434fbed8765f70fb30571e40ad288c1a66
表示されたコマンドをworkerノードで実行することで、K8sクラスタへのworkerノードの追加が完了する。
code:shell
pi@worker-rpi4$ sudo kubeadm join 192.168.3.101:6443 --token cgn745.x8gzni9rgwcuqub5 --discovery-token-ca-cert-hash sha256:511f26c4010e4d54e2f8ebafb16204434fbed8765f70fb30571e40ad288c1a66
preflight Running pre-flight checks
WARNING IsDockerSystemdCheck: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". Please follow the guide at https://kubernetes.io/docs/setup/cri/
WARNING SystemVerification: missing optional cgroups: hugetlb
preflight Reading configuration from the cluster...
preflight FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
kubelet-start Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
kubelet-start Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
kubelet-start Starting the kubelet
kubelet-start Waiting for the kubelet to perform the TLS Bootstrap...
kubelet-check Initial timeout of 40s passed.
This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.
Run 'kubectl get nodes' on the control-plane to see this node join the cluster.
追加されたことは、以下のように確認できる。
code:shell
pi@master-rpi4$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
master-rpi4 Ready master 47h v1.19.4
worker-rpi3p NotReady <none> 46h v1.19.4
worker-rpi4 Ready <none> 2m37s v1.20.0
#RaspberryPi
#Kubernetes
#Docker
#Linux